﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ConsumerManage_ConsumerSearchEdit : System.Web.UI.Page, Frame.Pages.IDetailEditManPage<DAL.BI_Consumer>
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public int ComID
    {
        get
        {
            int i = 0;
            if (int.TryParse(Request.QueryString["comid"], out i))
            {
                return i;
            }
            else
            {
                return -1;
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(this.tbxSearch.Text.Trim()))
        {
            return;
        }
        if (ComID>=0)
        {
            BackUrl = string.Format("~/ConsumerManage/RefCompanyEdit.aspx?comid={0}", ComID);
            ScriptBackUrl = string.Format("RefCompanyEdit.aspx?comid={0}", ComID);
        }
        else
        {
            BackUrl = "~/ConsumerManage/EditConsumer.aspx";
            ScriptBackUrl = "EditConsumer.aspx";
        }
        
        Session["model"] = Frame.Pages.RefrenceContext<DAL.BI_Consumer>.Copy(this);
        using (DAL.CMSDALDataContext DataContext = new DAL.CMSDALDataContext())
        {
            DAL.BI_Consumer model =  DataContext.BI_Consumer.FirstOrDefault(o=>o.PhoneNum==this.tbxSearch.Text.Trim());
            if (model != null)
            {
                Response.Redirect(string.Format("~/ConsumerManage/EditDetailConsumer.aspx?KeyID={0}", model.ConsumerID));
            }
            else
            {
                Frame.Global.GlobalFunctions.AlertToUrl("点击确定新增客户信息！",
                    string.Format("EditDetailConsumer.aspx?PhoneNum={0}{1}",
                    this.tbxSearch.Text.Trim(),
                    (ComID<0?string.Empty:string.Format("&comid={0}",ComID))
                    ));
                //Response.Redirect(string.Format("~/ConsumerManage/EditDetailConsumer.aspx?PhoneNum={0}", this.tbxSearch.Text.Trim()));
            }
        }
        
    }

    #region IDetailEditManPage<BI_Consumer> 成员

    public string BackUrl
    {
        get;
        set;
    }

    public DAL.BI_Consumer Model
    {
        get;
        set;
    }

    public string ScriptBackUrl
    {
        get;
        set;
    }

    #endregion
}